/*
 * wdt_drv.c
 *
 * Created: 2018/7/29 8:28:41
 *  Author: admin
 */ 


#include "wdt_drv.h"



void wdtdrv_disable(void)
{
	uint8_t save_int=( SREG & 0x80);
	cli();
	Ack_wdt_reset();
	wdt_disable();
	if(save_int) { sei(); }
}

void wdtdrv_enable( uint8_t timeout )
{
	uint8_t save_int=( SREG & 0x80);
	cli();
	Ack_wdt_reset();
	wdt_enable(timeout);
	if(save_int) { sei(); }
}

void wdtdrv_interrupt_enable( uint8_t timeout )
{
	uint8_t save_int=( SREG & 0x80);
	Ack_wdt_reset();
	__asm__ __volatile__ (  \
		"in __tmp_reg__,__SREG__" "\n\t"    \
		"cli" "\n\t"    \
		"wdr" "\n\t"    \
		"sts %0,%1" "\n\t"  \
		"out __SREG__,__tmp_reg__" "\n\t"   \
		"sts %0,%2" \
		: /* no outputs */  \
		: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
		"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
		"r" ((uint8_t) ((timeout & 0x08 ? _WD_PS3_MASK : 0x00) | \
		_BV(WDIE) | (timeout & 0x07)) ) \
		: "r0"  \
	);
	if(save_int) { sei(); }
}